# config/world_rules.py
from typing import Dict, List
from enum import Enum

class DifficultyLevel(Enum):
    EASY = "简单"
    NORMAL = "普通" 
    HARD = "困难"
    EXPERT = "专家"
    MASTER = "大师"

class WorldRules:
    """世界规则配置"""
    
    def __init__(self, difficulty: DifficultyLevel = DifficultyLevel.NORMAL):
        self.difficulty = difficulty
        self.rules = self._load_rules()
    
    def _load_rules(self) -> Dict:
        """加载规则配置"""
        base_rules = {
            "time_limits": {
                "total_cycles": 1000,
                "time_per_cycle": 1000,
                "iron_curtain_increment": 10
            },
            "factor_development": {
                "max_level": 50,
                "exp_required_base": 100,
                "exp_growth_rate": 1.2,
                "attribute_growth_base": 5
            },
            "combat_rules": {
                "base_damage_multiplier": 1.0,
                "critical_chance_base": 0.05,
                "dodge_chance_base": 0.1,
                "healing_efficiency": 1.0
            },
            "event_system": {
                "event_frequency": 0.1,
                "max_concurrent_events": 3,
                "event_duration_range": (20, 60)
            }
        }
        
        # 根据难度调整规则
        difficulty_multipliers = {
            DifficultyLevel.EASY: 0.7,
            DifficultyLevel.NORMAL: 1.0,
            DifficultyLevel.HARD: 1.3,
            DifficultyLevel.EXPERT: 1.6,
            DifficultyLevel.MASTER: 2.0
        }
        
        multiplier = difficulty_multipliers.get(self.difficulty, 1.0)
        
        # 应用难度调整
        adjusted_rules = base_rules.copy()
        adjusted_rules["combat_rules"]["base_damage_multiplier"] *= multiplier
        adjusted_rules["event_system"]["event_frequency"] *= multiplier
        
        return adjusted_rules
    
    def get_rule(self, category: str, key: str):
        """获取特定规则"""
        return self.rules.get(category, {}).get(key)
    
    def update_difficulty(self, new_difficulty: DifficultyLevel):
        """更新难度级别"""
        self.difficulty = new_difficulty
        self.rules = self._load_rules()